Set target using config file
authorfpgaminer <fpgaminer@bitcoin-mining.com>
Sat, 30 Jan 2016 08:31:42 +0000 (00:31 -0800)
committerfpgaminer <fpgaminer@bitcoin-mining.com>
Sat, 30 Jan 2016 08:31:42 +0000 (00:31 -0800)
src/cargo/ops/cargo_compile.rs
src/doc/config.md
tests/test_cargo_cross_compile.rs

index b4cebffd6e5d7a4779ef94a2ee542092af359164..ba7716f12b54e0fd324a52b80cf71d17b8359588 100644 (file)
@@ -412,6 +412,7 @@ fn source_ids_from_config(config: &Config, cur_path: &Path)
 /// configured options are:
 ///
 /// * build.jobs
+/// * build.target
 /// * target.$target.ar
 /// * target.$target.linker
 /// * target.$target.libfoo.metadata
@@ -432,6 +433,8 @@ fn scrape_build_config(config: &Config,
         None => None,
     };
     let jobs = jobs.or(cfg_jobs).unwrap_or(::num_cpus::get() as u32);
+    let cfg_target = try!(config.get_string("build.target")).map(|s| s.0);
+    let target = target.or(cfg_target);
     let mut base = ops::BuildConfig {
         jobs: jobs,
         requested_target: target.clone(),
index b45ae23ad2839923d818289e27dd42282ce83692..d911e87bf2f000bfebe8318cc7b03823871a80be 100644 (file)
@@ -84,6 +84,7 @@ timeout = 60000   # Timeout for each HTTP request, in milliseconds
 jobs = 1               # number of jobs to run by default (default to # cpus)
 rustc = "rustc"        # the rust compiler tool
 rustdoc = "rustdoc"    # the doc generator tool
+target = "triple"      # build for the target triple
 target-dir = "target"  # path of where to place all generated artifacts
 ```
 
index 06686bf9087ede20908ad6181af6641550d569c7..6536c526e0d4ebd8e89a2d255154fe339b73bbe3 100644 (file)
@@ -78,6 +78,42 @@ test!(simple_cross {
                 execs().with_status(0));
 });
 
+test!(simple_cross_config {
+    if disabled() { return }
+
+    let p = project("foo")
+        .file(".cargo/config", &format!(r#"
+            [build]
+            target = "{}"
+        "#, alternate()))
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.0"
+            authors = []
+            build = "build.rs"
+        "#)
+        .file("build.rs", &format!(r#"
+            fn main() {{
+                assert_eq!(std::env::var("TARGET").unwrap(), "{}");
+            }}
+        "#, alternate()))
+        .file("src/main.rs", &format!(r#"
+            use std::env;
+            fn main() {{
+                assert_eq!(env::consts::ARCH, "{}");
+            }}
+        "#, alternate_arch()));
+
+    let target = alternate();
+    assert_that(p.cargo_process("build").arg("-v"),
+                execs().with_status(0));
+    assert_that(&p.target_bin(&target, "foo"), existing_file());
+
+    assert_that(process(&p.target_bin(&target, "foo")),
+                execs().with_status(0));
+});
+
 test!(simple_deps {
     if disabled() { return }